package com.asa.jihe.utils;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Copy {

	/**
	 * 复制点集
	 * @param points
	 * @return
	 */
	public static List<Point> newpoints(List<Point> points){
		
		List<Point> newpoints = new LinkedList<>();
		
		for (int i = 0; i < points.size(); i++) {
			newpoints.add(points.get(i));
		}
		
		return newpoints;
		
	}
	
	
	
	
	
	public static List<Point> graphtopoints(Graph graph){
		
		List<Line> lines = graph.lines;
		List<Point> resultlines = line2pointsort(lines);
		return resultlines;
		
	}
	
	
	
	
	public static List<Point> line2pointsort(List<Line> lines){
		
		List<Point> resultlines = new LinkedList();
		for (int i = 0; i < lines.size(); i++) {
			
			Line line = lines.get(i);
			boolean containss = resultlines.contains(line.spoint);
			boolean containse = resultlines.contains(line.epoint);
			
			if (!containss) {
				resultlines.add(line.spoint);
			}
			if (!containse) {
				resultlines.add(line.epoint);
			}

		}
		return resultlines;
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	public static List<Line> graphtopoints(List<Point> points){
		
		List<Line> result = new ArrayList<Line>();
		for (int i = 0; i < points.size()-1; i++) {
			
			Point spoint = points.get(i);
			Point epoint = points.get(i+1);

			Line line = new Line();
			line.spoint = spoint;
			line.epoint = epoint;
			
			
			result.add(line);
		}

		Point spoint = points.get(points.size()-1);
		Point epoint = points.get(0);

		Line line = new Line();
		line.spoint = spoint;
		line.epoint = epoint;
		result.add(line);

		
		return result;
		
		
	}

	
	
	/**
	 * 将一个线段集合，首尾次序连接point
	 * @param lines
	 * @return
	 */
	public static List<Point> line2point(List<Line> lines){
		
		
		List<Line> asa = new LinkedList<>();
		asa.add(lines.get(0));
		
		while(asa.size()<lines.size()) {
			
			for (int i = 1; i < lines.size(); i++) {
				Line line = lines.get(i);
				
				
				if (asa.contains(line)) {	
					continue;
				}
				
				Line line2 = asa.get(asa.size()-1);
				
				if (line2.epoint == line.spoint) {
					asa.add(line);
					break;
				}
				
			}
	
		}
		
		
		
		
		
		List<Point> result = line2pointsort(asa);

		
		return result;
		
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
